package com.bawei.module_base.net.util

import android.util.Log
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import java.io.IOException

/**
 * 作者:
 * 时间:
 * 描述:头参拦截器
 */
class HeaderInterceptor : Interceptor {

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder: Request.Builder = chain.request().newBuilder()
        if (MMKVUtil.getUserId()!=0 && MMKVUtil.getSessionId()!=""){
            Log.i(
                "TAG",
                "intercept: userId" + MMKVUtil.getUserId() + "sessionId" + MMKVUtil.getSessionId()
            )
            builder.addHeader("userId", "" + MMKVUtil.getUserId())
            builder.addHeader("sessionId", MMKVUtil.getSessionId())
        }
        return chain.proceed(builder.build())
    }
}
